﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BDCS.BLL;
using BDCS.Model;

namespace BDCS.UI
{
    public partial class AddSubBuildNames : Form
    {
        #region 成员字段
        private BDCS.BLL.T_SubBuildName bllSubBuildName;
        private BDCS.Model.T_SubBuildName modelSubBuildTypes;
        private DataSet dataSet;
        private BDCS.BLL.T_SubBuildTyppes subBuildTypes;
        #endregion
        #region 构造函数
        public AddSubBuildNames()
        {
            InitializeComponent();
        }
        #endregion
        #region 成员事件
        private void AddSubBuildName_Load(object sender, EventArgs e)
        {
            CommBoxSubBuildNameDataBinding();
        }
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.txtSubBuildName.Text = string.Empty;
            this.txtSubBuildNameDescribe.Text = string.Empty;
        }
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtSubBuildName.Text.Trim()))
            {
                bllSubBuildName = new BLL.T_SubBuildName();
                modelSubBuildTypes = new Model.T_SubBuildName();
                modelSubBuildTypes.SBTID = Convert.ToInt32(this.cobSubBuildName.SelectedValue);
                modelSubBuildTypes.SBNName = this.txtSubBuildName.Text.Trim();
                modelSubBuildTypes.SBNDescribe = this.txtSubBuildNameDescribe.Text.Trim();
                dataSet = new DataSet();
                dataSet = bllSubBuildName.GetList("SBNName=" + "'" + this.txtSubBuildName.Text.Trim() + "'");
                if (dataSet.Tables[0].Rows.Count == 0)
                {
                    if (bllSubBuildName.Add(modelSubBuildTypes) != 0)
                    {
                        MessageBox.Show("添加子类建筑下子类建筑名称成功！");
                    }
                    else
                    {
                        MessageBox.Show("添加子类建筑下子类建筑名称失败，请重新输入！");
                    }
                }
                else
                {
                    MessageBox.Show("该子类建筑下子类建筑名称已经存在，请重新输入！");
                }
            }
            else
            {
                MessageBox.Show("请输入子类建筑名称！");
            }
        }
        #endregion
        #region 成员方法
        private void CommBoxSubBuildNameDataBinding()
        {
            subBuildTypes = new BLL.T_SubBuildTyppes();
            dataSet = new DataSet();
            dataSet = subBuildTypes.GetAllList();
            this.cobSubBuildName.DataSource = dataSet.Tables[0];
            this.cobSubBuildName.DisplayMember = "SBTName";
            this.cobSubBuildName.ValueMember = "SBTID";
        }
        #endregion
    }
}
